//
//  ByRecordListView.m
//  recordworktool_ios
//
//  Created by mc on 2017/12/7.
//  Copyright © 2017年 ZhangZhanbin. All rights reserved.
//

#import "ByRecordListView.h"
#import "JSONKit.h"

@implementation ByRecordListView

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        CGFloat width = SCREEN_WIDTH - 20;
        UILabel *timeLabel = [[UILabel alloc] init];
        [self addSubview:timeLabel];
        [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(10);
            make.centerY.equalTo(self).offset(0);
            make.size.mas_equalTo(CGSizeMake(30, 20));
        }];
        timeLabel.textAlignment = NSTextAlignmentCenter;
        timeLabel.text = @"1日";
        timeLabel.font = FONT(12);
        timeLabel.textColor = TEXT_COLOR;
        
        
        UIButton *detailBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:detailBtn];
        [detailBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-10);
            make.centerY.equalTo(self).offset(0);
            make.size.mas_equalTo(CGSizeMake(60, 22));
        }];
        detailBtn.titleLabel.font = FONT(12);
        [detailBtn setTitle:@"明细" forState:UIControlStateNormal];
        [detailBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        detailBtn.backgroundColor = BY_THEME_COLOR;
        detailBtn.layer.cornerRadius = 10;
        
        UILabel *nameLabel = [[UILabel alloc] init];
        [self addSubview:nameLabel];
        [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(timeLabel.mas_right).offset(10);
            make.centerY.equalTo(self).offset(0);
            make.size.mas_equalTo(CGSizeMake(40, 20));
        }];
        nameLabel.font = FONT(12);
        nameLabel.textColor = TEXT_COLOR;
        nameLabel.text = @"王工头";
        
        UILabel *priceLabel = [[UILabel alloc] init];
        [self addSubview:priceLabel];
        [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(detailBtn.mas_left).offset(-10);
            make.centerY.equalTo(self).offset(0);
            make.size.mas_equalTo(CGSizeMake(60, 20));
        }];
        priceLabel.font = FONT(12);
        priceLabel.textColor = TEXT_COLOR;
        priceLabel.text = @"¥500";
       
        
        UILabel *valueLabel = [[UILabel alloc] init];
        [self addSubview:valueLabel];
        [valueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(nameLabel.mas_right).offset(10);
            make.right.equalTo(priceLabel.mas_left).offset(-10);
            make.centerY.equalTo(self).offset(0);
            make.height.mas_equalTo(@20);
        }];
        valueLabel.font = FONT(12);
        valueLabel.textAlignment = NSTextAlignmentCenter;
        valueLabel.textColor = TEXT_COLOR;
        valueLabel.text = @"8小时（一个工）";
        
        self.timeLabel = timeLabel;
        self.nameLabel = nameLabel;
        self.valueLabel = valueLabel;
        self.priceLabel = priceLabel;
        self.detailBtn = detailBtn;
        
        
    }
    return self;
}

- (void)setNetModel:(ByNetModel *)netModel{
    _netModel = netModel;
    NSString *dayStr = [_netModel.daytime substringFromIndex:6];
    if (BY_USER.isWorker.integerValue == 1) {
        self.nameLabel.text = _netModel.overseer_name;
        self.timeLabel.text = [NSString stringWithFormat:@"%ld日", dayStr.integerValue];
        self.priceLabel.text = [NSString stringWithFormat:@"¥%.2f", _netModel.money.floatValue];
        NSMutableDictionary *dic;
        NSString *normal_work_time;
        if (netModel.extra && netModel.extra.length > 0 && ![netModel.extra isEqualToString:@"[]"]) {
            dic = [netModel.extra mutableObjectFromJSONString];
            normal_work_time = dic[@"normal_worktime"];
        }
        //点工
        if ([netModel.item_type_key isEqualToString:@"00S002003"]) {
            self.valueLabel.text = [NSString stringWithFormat:@"(%ld个工)点工",normal_work_time.integerValue / 8];
            self.priceLabel.textColor = GREEN_COLOR;
            self.priceLabel.text = [NSString stringWithFormat:@"+¥%.2f",_netModel.money.floatValue];
            //包工
        }else if ([netModel.item_type_key isEqualToString:@"00S002002"]){
            
            self.valueLabel.text = [NSString stringWithFormat:@"包工"];
            self.priceLabel.textColor = GREEN_COLOR;
            self.priceLabel.text = [NSString stringWithFormat:@"+¥%.2f",_netModel.money.floatValue];
            
            //借支
        }else if ([netModel.item_type_key isEqualToString:@"00S002004"]){
            
            self.valueLabel.text = @"借支";
            self.priceLabel.textColor = [UIColor redColor];
            self.priceLabel.text = [NSString stringWithFormat:@"-¥%.2f",_netModel.money.floatValue];
            
            //结算
        }else if ([netModel.item_type_key isEqualToString:@"00S002005"]){
            
            self.valueLabel.text = @"结算";
            self.priceLabel.textColor = [UIColor redColor];
            self.priceLabel.text = [NSString stringWithFormat:@"-¥%.2f",_netModel.money.floatValue];
        }
    }
}


@end
